import {reqCategoryList,reqBannerList,reqFlooerList} from '@/api'
//存放数据的仓库
const state = {
    //仓库里的数据类型不能随意定义，取决于服务器返回的数据类型
    categoryList:[],
    bannerList:[],
    flooerList:[]
}
//书写业务逻辑
const actions = {
    //通过api里的接口向服务器发起请求获取数据
    async categoryList(){
        //reqCategoryList返回的是一个promise对象，拿到它成功的回调
        let result = await reqCategoryList();
        if(result.code === 200){
            this.commit('CATEGORYLIST',result.data)
        }
    },
    async getBannerList(){
        let result = await reqBannerList();
        if(result.code === 200){
            this.commit('BANNERLIST',result.data)
        }
    },
    async getflooerList(){
        let result = await reqFlooerList();
        if(result.code == 200){
            this.commit('FLOOERLIST',result.data)
        }
    }
}
//修改数据的唯一手段
const mutations = {
    CATEGORYLIST(state,categoryList){
        state.categoryList = categoryList
    },
    BANNERLIST(state,bannerList){
        state.bannerList = bannerList
    },
    FLOOERLIST(state,flooerList){
        state.flooerList = flooerList
    }
}
//计算属性
const getters = {}

export default {
    state,mutations,actions,getters
}